import {
	getToken
} from '@/utils/auth.js'
import request from '@/utils/request';

export default function upload(options) {
	return new Promise((resolve, reject) => {
		uni.uploadFile({
			url: options.url,
			filePath: options.filePath,
			name: options.name,
			formData: options.formData || {},
			header: {
				'Authorization': 'Bearer ' + getToken()
			},
			success: (uploadRes) => {
				if (uploadRes.statusCode === 200) {
					// 上传成功
					const data = JSON.parse(uploadRes.data);
					resolve(data);
				} else {
					reject(uploadRes.statusCode);
				}
			},
			fail: (error) => {
				// 上传失败
				reject(error);
			}
		});
	});
}